package com.haitonghop.modules.truyentranh;

import org.json.JSONObject;

import com.haitonghop.utils.StringUtils;

import android.util.Log;

public class TruyenTranhChapterData {
	public String id = "";
	String subId = "";
	public String name = "";
	String nameSeo = "";
	public String readUrl = "";
	String titleUrl = "";
	public String avatar = "";
	
	public TruyenTranhChapterData(){
		
	}
	
	public TruyenTranhChapterData(JSONObject data, String avatar){
		if(data != null){
			try{
				setName(data.has("titleUrl") ? data.getString("titleUrl") : "");
				setReadUrl(data.has("readUrl") ? data.getString("readUrl") : "");
				
				this.avatar = data.has("avatar") ? data.getString("avatar") : "";
				
				if(this.avatar == null || (this.avatar != null && this.avatar.length() == 0)){
					this.avatar = avatar != null ? avatar : "";
				}
				
				String tmpName = getName();
				id = StringUtils.MD5(readUrl);
				if(tmpName.indexOf("Đọc truyện tranh") != -1){
					setName(tmpName.replace("Đọc truyện tranh", ""));
				}
				
				Log.i("TruyenTranhChapterData", getName());
			} catch(Exception e){
				
			}
		}
	}
	
//	public TruyenTranhChapterData(JSONObject data){
//		if(data != null){
//			try{
//				setName(data.has("titleUrl") ? data.getString("titleUrl") : "");
//				setReadUrl(data.has("readUrl") ? data.getString("readUrl") : "");
//				String tmpName = getName();
//				id = StringUtils.MD5(readUrl);
//				if(tmpName.indexOf("Đọc truyện tranh") != -1){
//					setName(tmpName.replace("Đọc truyện tranh", ""));
//				}
//				
//				Log.i("TruyenTranhChapterData", getName());
//			} catch(Exception e){
//				
//			}
//		}
//	}
	
	public String getName(){
		return this.name;
	}
	
	public String getUrl(){
		return this.getReadUrl();
	}
	
	public String getAvatar(){
		return this.avatar;
	}

	public void setName(String name) {
		if(name != null)
			this.name = name.trim();
	}

	public String getReadUrl() {
		return readUrl;
	}

	public void setReadUrl(String readUrl) {
		this.readUrl = readUrl;
	}
	
}
